package com.ywj.boot_security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfigWay2 extends WebSecurityConfigurerAdapter {
    @Bean
    public PasswordEncoder passwordEncoder(){
        //提供加密方式
        return new BCryptPasswordEncoder();  //在这里一定要制定加密方式，否则在项目启动时不会报错但是在登陆是会提示密码错误
    }

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .passwordEncoder(passwordEncoder())  // 指定加密方式
                .withUser("ywj").password(passwordEncoder().encode("1234567")).roles("admin")
                .and()
                .withUser("ywj1").password(passwordEncoder().encode("1234567")).roles("USER");
    }
}
